/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author RENZO
 */
public class dataAccess {
    
    private static Connection x = null;
    
    private static String usr="postgres";
    private static String server = "localhost";
    private static String database = "cielsa";
    private static String driver = "org.postgresql.Driver"; 
    private static String clv="adminadmin";
    private static String url="jdbc:postgresql://"+server+"/"+database+"?user="+usr+"&password="+clv;
    private dataAccess(){
        
    }
    
    public static Connection getConnection(){
        try {
            if(x == null || x.isClosed() == true){
                try {
                    Class.forName(driver);
                    x = DriverManager.getConnection(url);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(dataAccess.class.getName()).log(Level.SEVERE, null, ex);
                }
                //x.setAutoCommit(false);//Requerirá siempre de finalizar una transacción con commit, o rollBack en caso de error
            }
        } catch (SQLException ex) {
            Logger.getLogger(dataAccess.class.getName()).log(Level.SEVERE,null,ex);
        }
        return x;
    }
    
    public static void closeConnection(){
        if(x != null){
            try {
                x.close();
            } catch (SQLException ex) {
                Logger.getLogger(dataAccess.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

}
